function Initial() {

	$("#securityCheckDiv").hide();

	$("#templateDiv").hide();

	$("#submitDiv").hide();

	$("#responseDiv").hide();

}

/**
 * send soap
 * 
 * 
 */

function sendSoap() {

	$("#sendSoap").click(function() {

		if ($("#securityCheck").prop('checked')) {
			sendSecuritySoap();

		} else {

			sendNormalSoap();
		}

	});

}

function sendSecuritySoap() {

	var data = $("#Result").val();

	var operationSelect = $("#operationSelect").val();

	var OperationName = operationSelect.split('|')[0];

	var requestName = operationSelect.split('|')[1];

	var userName = $("#account").val();

	var password = $("#password").val();

	var passwordType = $("#passwordType").val();

	var sendData = {
		"data" : data,
		"operationName" : OperationName,
		"requestName" : requestName,
		"userName" : userName,
		"password" : password,
		"passwordType" : passwordType
	};

	$.ajax({
		url : "http://localhost:8080/SpringTest/rest/sendSoapSecurity",
		data : sendData,
		dataType : "json",
	}).done(function(data) {

		$("#response").val(data["Response"]);

		$("#responseDiv").show();
	});

}

function sendNormalSoap() {

	var data = $("#Result").val();

	var operationSelect = $("#operationSelect").val();

	var OperationName = operationSelect.split('|')[0];

	var requestName = operationSelect.split('|')[1];

	var sendData = {
		"data" : data,
		"operationName" : OperationName,
		"requestName" : requestName
	};

	$.ajax({
		url : "http://localhost:8080/SpringTest/rest/sendSoap",
		data : sendData,
		dataType : "json",
	}).done(function(data) {

		$("#response").val(data["Response"]);

		$("#responseDiv").show();
	});

}

function securityCheck() {
	$("#securityDiv").hide();
	$("#securityCheck").click(function() {
		$("#securityDiv").toggle(200);

	})

}

function autoset() {
	var checkstring = "${isInitial}";
	var checkstring2 = $("#wsdltest").val();
	if ($("#wsdltest").val() == "true") {
		alert("in");
		$("#urlSubmit").hide();
		var sendData = "https://wd2-impl-services1.workday.com/ccx/service/pwc_dpt1/Staffing/v25.0?wsdl";
		$.ajax({
			url : "http://localhost:8080/ConverstionTool/rest/operationMap",
			beforeSend : function() {
				$("#moduleDiv").show();
			},
			data : {
				"url" : sendData
			},
			dataType : "json",
		}).done(function(data) {
			var receiveData = data;
			$("#selectDiv").append("<select id='operationSelect' class='selectpicker'></select>");
			$.each(data, function(key, value) {
				$("#operationSelect").append("<option value=\"" + key + "\">" + key + "</option>");
			});
			$("#operationSelect").change(function() {
				var template = receiveData[$(this).val()];
				$(Result).val(template);
			});
			$("#securityCheckDiv").show();
			$("#templateDiv").show();
			$("#submitDiv").show();
			$("#moduleDiv").hide();
		})
	}
}

function sendURL() {

	$("#urlSubmit").click(function() {

		var sendData = $("#url").val();

		$.ajax({
			url : "http://localhost:8080/ConverstionTool/rest/operationMap",
			beforeSend : function() {
				$("#moduleDiv").show();
			},
			data : {
				"url" : sendData
			},
			dataType : "json",
		}).done(function(data) {

			var receiveData = data;

			$("#selectDiv").append("<select id='operationSelect' class='selectpicker'></select>");

			$.each(data, function(key, value) {
				$("#operationSelect").append("<option value=\"" + key + "\">" + key + "</option>");
			});

			$("#operationSelect").change(function() {

				var template = receiveData[$(this).val()];

				$(Result).val(template);

			});

			$("#securityCheckDiv").show();

			$("#templateDiv").show();

			$("#submitDiv").show();

			$("#moduleDiv").hide();

		})

	});

}

/**
 * 
 */

$(function() {

	Initial();

	sendURL();

	securityCheck();

	sendSoap();

	autoset();

});